4e6e64160d3ee047e0e21456ebe5eb636c377cdf
[lhc/web/wiklou.git] / tests / RunTests.php
1 <?php
2
3 if( php_sapi_name() != 'cli' ) {
4 echo 'Must be run from the command line.';
5 die( -1 );
6 }
7
8 error_reporting( E_ALL );
9 define( "MEDIAWIKI", true );
10
11 set_include_path( get_include_path() . PATH_SEPARATOR . 'PHPUnit' );
12 set_include_path( get_include_path() . PATH_SEPARATOR . '..' );
13 require_once( 'PHPUnit.php' );
14
15 $testOptions = array(
16 'mysql4' => array(
17 'server' => null,
18 'user' => null,
19 'password' => null,
20 'database' => null ),
21 'postgresql' => array(
22 'server' => null,
23 'user' => null,
24 'password' => null,
25 'database' => null ),
26 );
27
28 if( file_exists( 'LocalTestSettings.php' ) ) {
29 include( './LocalTestSettings.php' );
30 }
31
32 $tests = array(
33 'GlobalTest',
34 'DatabaseTest',
35 'SearchMySQL4Test',
36 'ArticleTest',
37 'SanitizerTest',
38 'CtypeTest'
39 );
40 foreach( $tests as $test ) {
41 require_once( $test . '.php' );
42 $suite = new PHPUnit_TestSuite( $test );
43 $result = PHPUnit::run( $suite );
44 echo $result->toString();
45 }
46
47 /**
48 * @param string $serverType
49 * @param array $tables
50 */
51 function &buildTestDatabase( $serverType, $tables ) {
52 global $testOptions, $wgDBprefix;
53 $wgDBprefix = 'parsertest';
54 $db =& new Database(
55 $testOptions[$serverType]['server'],
56 $testOptions[$serverType]['user'],
57 $testOptions[$serverType]['password'],
58 $testOptions[$serverType]['database'] );
59 if( $db->isOpen() ) {
60 if (!(strcmp($db->getServerVersion(), '4.1') < 0 and stristr($db->getSoftwareLink(), 'MySQL'))) {
61 # Database that supports CREATE TABLE ... LIKE
62 foreach ($tables as $tbl) {
63 $newTableName = $db->tableName( $tbl );
64 #$tableName = $this->oldTableNames[$tbl];
65 $tableName = $tbl;
66 $db->query("CREATE TEMPORARY TABLE $newTableName (LIKE $tableName INCLUDING DEFAULTS)");
67 }
68 } else {
69 # Hack for MySQL versions < 4.1, which don't support
70 # "CREATE TABLE ... LIKE". Note that
71 # "CREATE TEMPORARY TABLE ... SELECT * FROM ... LIMIT 0"
72 # would not create the indexes we need....
73 foreach ($tables as $tbl) {
74 $res = $db->query("SHOW CREATE TABLE $tbl");
75 $row = $db->fetchRow($res);
76 $create = $row[1];
77 $create_tmp = preg_replace('/CREATE TABLE `(.*?)`/', 'CREATE TEMPORARY TABLE `'
78 . $wgDBprefix . '\\1`', $create);
79 if ($create === $create_tmp) {
80 # Couldn't do replacement
81 wfDie( "could not create temporary table $tbl" );
82 }
83 $db->query($create_tmp);
84 }
85
86 }
87 return $db;
88 } else {
89 // Something amiss
90 return null;
91 }
92 }
93
94 ?>